package com.ruoyi.admin.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.admin.domain.CorpCompanyAgents;
import com.ruoyi.admin.service.ICorpCompanyAgentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 授权应用Controller
 * 
 * @author Jimmy
 * @date 2022-08-03
 */
@RestController
@RequestMapping("/admin/corp_company_agents")
public class CorpCompanyAgentsController extends BaseController
{
    @Autowired
    private ICorpCompanyAgentsService corpCompanyAgentsService;

    /**
     * 查询授权应用列表
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_agents:list')")
    @GetMapping("/list")
    public TableDataInfo list(CorpCompanyAgents corpCompanyAgents)
    {
        startPage();
        List<CorpCompanyAgents> list = corpCompanyAgentsService.selectCorpCompanyAgentsList(corpCompanyAgents);
        return getDataTable(list);
    }

    /**
     * 导出授权应用列表
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_agents:export')")
    @Log(title = "授权应用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CorpCompanyAgents corpCompanyAgents)
    {
        List<CorpCompanyAgents> list = corpCompanyAgentsService.selectCorpCompanyAgentsList(corpCompanyAgents);
        ExcelUtil<CorpCompanyAgents> util = new ExcelUtil<CorpCompanyAgents>(CorpCompanyAgents.class);
        util.exportExcel(response, list, "授权应用数据");
    }

    /**
     * 获取授权应用详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_agents:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(corpCompanyAgentsService.selectCorpCompanyAgentsById(id));
    }

    /**
     * 新增授权应用
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_agents:add')")
    @Log(title = "授权应用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CorpCompanyAgents corpCompanyAgents)
    {
        return toAjax(corpCompanyAgentsService.insertCorpCompanyAgents(corpCompanyAgents));
    }

    /**
     * 修改授权应用
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_agents:edit')")
    @Log(title = "授权应用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CorpCompanyAgents corpCompanyAgents)
    {
        return toAjax(corpCompanyAgentsService.updateCorpCompanyAgents(corpCompanyAgents));
    }

    /**
     * 删除授权应用
     */
    @PreAuthorize("@ss.hasPermi('admin:corp_company_agents:remove')")
    @Log(title = "授权应用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(corpCompanyAgentsService.deleteCorpCompanyAgentsByIds(ids));
    }
}
